<template>
  <!-- Default box -->
  <div class="card">
    <div class="card-header">
      <h3 class="card-title">{{ stageTitle }}</h3>
      <div class="card-tools">
        <router-link to="/stage/batchadd" class="btn btn-dark"
          ><i class="el-icon-circle-plus-outline"></i>批量增加</router-link
        >
        <router-link to="/stage/add" class="btn btn-dark"
          ><i class="el-icon-circle-plus-outline"></i>增加</router-link
        >
        <a href="#" @click.prevent="toModify()" class="btn btn-dark"
          ><i class="el-icon-edit"></i>修改</a
        >
        <a href="#" @click.prevent="doDelete()" class="btn btn-dark"
          ><i class="el-icon-remove-outline"></i>删除</a
        >
        <a href="#" @click.prevent="toView()" class="btn btn-dark"
          ><i class="el-icon-view"></i>查看</a
        >
      </div>
    </div>
    <div class="card-body">
      <router-view></router-view>
    </div>
  </div>
  <!-- /.card-body -->
</template>
<script>
export default {
  name: "StageMain",
  data() {
    return {
      stageTitle: "阶段管理",
      id: 0,
    };
  },
  methods: {
    toModify() {
      if (this.id === 0) {
        this.$message({
          message: "请选中要修改的阶段",
          type: "warning",
        });
      } else {
        this.$router.push("/stage/modify/" + this.id);
      }
    },
    doDelete(id) {
      if (this.id === 0) {
        this.$message({
          message: "请选中要删除的阶段",
          type: "warning",
        });
      } else {
        this.$confirm("确定要删除吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.axiosJSON.get("/stage/delete?id=" + this.id).then((result) => {
              if (result.data.code == 0) {
                this.$message({
                  message: result.data.msg,
                  type: "success",
                });
                //如何刷新子组件的数据,使用事件发送机制
                this.oaevent.$emit("updateStageList");
              } else {
                this.$message.error({
                  message: result.data.msg,
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      }
    },
    toView() {
      if (this.id == 0) {
        alert("请选中要查看的阶段");
      } else {
        this.$router.push("/stage/view/" + this.id);
      }
    },
  },
};
</script>

<style>
</style>
